home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
PsL Monthly 1994 December
/
PSL Monthly Shareware CD-ROM (Public Software Library)(December 1994).bin
/
prgmming
/
dos
/
c1
/
less.c
< prev
next >
Wrap
C/C++ Source or Header
|
1990-04-20
|
3KB
|
63 lines
/*****************************************************\
* LESS Written by: Bruce Lowther [71520,2165] *
* *
* type <filename> | less <scoll length> *
* *
* Less is similar to More in MS-dos, but the scroll *
* length can be changed by entering the prefered *
* scroll length on the command line. *
* *
* Example: c:\>type less.c | less 10 *
* *
* This program is an example of combinations of *
* the stdin stream, CON stream, and command line *
* parameters. If you use this program, or find it *
* useful then yell "Thanks!" real loud, or drop me *
* mail. I would also like some constructive crit., *
* if you have any. *
\*****************************************************/
#include <stdio.h> /* for fopen(), getchar() and getc() */
#include <stdlib.h> /* for atoi() */
#define SMALL 15 /* value of scroll if none is specified */
main (int argc,char *argv[]) /* gets the command line parameters */
{
FILE *kbd; /* file used when CON is opened */
int counter = 1, /* the line number counter */
letter, /* character from stdin */
len; /* scroll length */
if (argc == 1) /* if no command line parameter,
set to standard scroll */
len = SMALL;
else /* else, take command line,
convert it to integer and use
it */
len = atoi(argv[1]);
while ((letter = getchar()) != EOF) /* loop until EOF on stdin. */
{
if (counter >= len) /* if counter has reached len,
then stop, and get input from
the CON (keyboard) */
{
printf("\n%d[LESS]", len);
kbd = fopen("CON","r"); /* open the CON, for read only
note that stdin has not been
closed. */
getc(kbd); /* get a character from the
keyboard */
fclose (kbd); /* close keyboard so input can
come from stdin once again. */
counter = 1;
}
if (letter == '\n') counter++; /* increment counter at each
newline character '\n' */
putchar(letter); /* put the next character onto
stdout. */
}
}